<include file="../Public/_header" />
<div class="so_main">
  <div class="page_tit">
  <if  condition="0 != $pid">
  <span class="right">
  <form action="{:U('admin/Tool/soSchool')}" method="post">
    <input type="hidden" name="pid" value="{$pid}" />
    <input type="text" name="kwd" id="school_key" />
    <input type="submit" value="搜索"/>
    </form>
    </span></if>
    学校管理
  </div>
  <div class="Toolbar_inbox">
    <if condition="0 != $pid"><a href="{:U('admin/Tool/school',array('pid'=>$back_id))}" class="btn_a"><span>返回</span></a></if>
    <if condition="0 == $pid">
    <a href="javascript:void(0);" class="btn_a" onclick="add();"><span>添加省份</span></a>
    <else/>
    <a href="javascript:void(0);" class="btn_a" onclick="add();"><span>添加学校</span></a>
    <a href="javascript:void(0);" class="btn_a" onclick="delsc();"><span>删除学校</span></a>
    </if>
   
  </div>
  
  <div class="list">
  <table id="area_list" width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <th style="width:30px;">
        <input type="checkbox" id="checkbox_handle" onclick="checkAll(this)" value="0">
        <label for="checkbox"></label>
    </th>
    <th class="line_l">ID</th>
    <th class="line_l">地区名称</th>
    <th class="line_l">操作</th>
  </tr>
  <volist id="vo" name="area">
      <tr overstyle='on' id="area_{$vo.area_id}">
        <td><if condition="0 == $pid">
        <input type="checkbox" name="checkbox" value="" disabled>
        <else/>
        <input type="checkbox" name="checkbox" id="checkbox2" onclick="checkon(this)" value="{$vo.area_id}">
        </if>
        </td>
        <td>{$vo.area_id}</td>
        <td><div style="float:left">
        <if condition="0 == $vo['pid']">
        <a href="{:U('admin/Tool/school',array('pid'=>$vo['area_id']))}" id="area_title_{$vo.area_id}">{$vo.title}</a>
        <else/>
        <span id="area_title_{$vo.area_id}">{$vo.title}</span>
        </if></div></td>
        <td>
            <a href="javascript:void(0);" onclick="edit({$vo['area_id']});">编辑</a> 
            <a href="javascript:void(0);" onclick="delsc({$vo['area_id']});">删除</a>  
        </td>
      </tr>
  </volist>
  </table>

  </div>
  <div class="Toolbar_inbox">
    <if condition="0 != $pid"><a href="{:U('admin/Tool/school',array('pid'=>$back_id))}" class="btn_a"><span>返回</span></a></if>
   <if condition="0 == $pid">
    <a href="javascript:void(0);" class="btn_a" onclick="add();"><span>添加省份</span></a>
    <else/>
    <a href="javascript:void(0);" class="btn_a" onclick="add();"><span>添加学校</span></a>
    <a href="javascript:void(0);" class="btn_a" onclick="delsc();"><span>删除学校</span></a>
    </if>
  </div>
</div>

<script>
    //鼠标移动表格效果
    $(document).ready(function(){
        $("tr[overstyle='on']").hover(
          function () {
            $(this).addClass("bg_hover");
          },
          function () {
            $(this).removeClass("bg_hover");
          }
        );
    });
    
    function checkon(o){
        if( o.checked == true ){
            $(o).parents('tr').addClass('bg_on') ;
        }else{
            $(o).parents('tr').removeClass('bg_on') ;
        }
    }
    
    function checkAll(o){
        if( o.checked == true ){
            $('input[name="checkbox"]').attr('checked','true');
            $('tr[overstyle="on"]').addClass("bg_on");
        }else{
            $('input[name="checkbox"]').removeAttr('checked');
            $('tr[overstyle="on"]').removeClass("bg_on");
        }
    }

    //获取已选择用户的ID数组
    function getChecked() {
        var gids = new Array();
        $.each($('input:checked'), function(i, n){
            gids.push( $(n).val() );
        });
        return gids;
    }
    //添加地区
    function add() {
        ui.box.load("{:U('admin/Tool/addSchool',array('pid'=>$pid))}", {title:'添加学校'});
    }
    
    //编辑地区
    function edit(area_id) {
        ui.box.load("{:U('admin/Tool/editSchool')}&area_id="+area_id, {title:'编辑学校'});
    }
    
    //删除地区
    function delsc(aid) {
        aid = aid ? aid : getChecked();
        aid = aid.toString();
        if(aid == '' || !confirm('删除成功后将无法恢复，确认继续？')) return false;

        //提交删除
        $.post("{:U('admin/Tool/doDelSchool')}", {ids:aid}, function(res){
	        if(res == '1') {
		        aid = aid.split(',');
		        $.each(aid, function(i,n){
		            $('#area_'+n).remove();
		        });
	            ui.success('删除成功');
	        }else {
	        	ui.success('删除失败');
	        }
        });
        
        
    }
</script>

<include file="../Public/_footer" />